//
//  MineMainViewModel.swift
//  GLUZSwift
//
//  Created by xyanl on 2025/5/14.
//

import UIKit

class MineMainViewModel {
    
    // 加载用户信息
   static func loadUserInfo(_ userId: String, completion: ((UserModel?) -> Void)? = nil) {
        let target = LoginAPI.userInfo(userId)
        YLRequest.request(target) { result in
            switch result {
            case .success(let res):
                if let dataDictionary = res.dataDictionary["data"] as? [String: Any] {
                    if let userModel = JsonUtil.modelFromDictionary(dataDictionary, UserModel.self) {
                        completion?(userModel)
                    } else {
                        completion?(nil)
                    }
                } else {
                    completion?(nil)
                }
                
            case .failure(let err):
                completion?(nil)
                YLHUD.showHint(.error, err.errMsg)
            }
        }
    }
    
}
